//
//  BaseViewController.h
//  CCFoundation
//
//  Created by CC on 2018/5/26.
//  Copyright © 2018年 CC. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "UIViewController+Lc.h"
#import "LcNavigationController.h"
#import "LcCellAdapter.h"
#import "LcNotificationCenter.h"

typedef NS_ENUM(NSInteger, ControllerViewState) {
  ControllerViewStateDisappeared,
  ControllerViewStateDisappearing,
  ControllerViewStateAppearing,
  ControllerViewStateAppeared,
};

typedef enum {
  NAVIGATION_ALIGNMENT_LEFT = 0,
  NAVIGATION_ALIGNMENT_MIDDLE,
  NAVIGATION_ALIGNMENT_RIGHT
} NavigationAlignment;

@class LcFont;

@interface BaseViewController : UIViewController <LcNotificationDelegate,
                                                  UIGestureRecognizerDelegate,
                                                  UITableViewDelegate,
                                                  LcCellAdapterDelegate>
@property(nonatomic, weak) IBOutlet UIView* topGuideBackgroundView;
@property(nonatomic, weak) NSLayoutConstraint* topGuideHeightConstraint;
@property(nonatomic, assign, readonly) ControllerViewState viewState;
@property(nonatomic, assign, readonly) BOOL viewAppeared;
@property(nonatomic, assign, readonly) BOOL viewDisappeared;
@property(nonatomic, assign, readonly) BOOL isControllerAnimating;
@property(nonatomic, weak) BaseViewController* fromViewController;
@property(nonatomic, assign, readonly) BOOL dismissed;
@property(nonatomic, weak, readonly) UITapGestureRecognizer* viewTapGesture;
@property(nonatomic, assign) BOOL isTabBarChildController;
@property(nonatomic, assign) BOOL needRefreshWhenAppear;

- (void)refreshWhenAppear;

- (void)navigationBack;

- (void)setWhiteNavigationBar;
- (void)setTransparentNavigationBar;

- (UIBarButtonItem*)whiteBarButtonItemWithTitle:(NSString*)title
                                         target:(id)target
                                         action:(SEL)action;
- (UIBarButtonItem*)darkBarButtonItemWithTitle:(NSString*)title
                                         target:(id)target
                                         action:(SEL)action;
- (UIBarButtonItem*)closeButtonItemWithTarget:(id)target action:(SEL)action;
- (UIBarButtonItem*)whiteCloseButtonItemWithTarget:(id)target
                                            action:(SEL)action;
- (UIBarButtonItem*)refreshButtonItemWithTarget:(id)target action:(SEL)action;
- (UIBarButtonItem*)searchButtonItemWithTarget:(id)target action:(SEL)action;
- (UIBarButtonItem*)customButtonItemWithImageName:(NSString*)imageName
                                           target:(id)target
                                           action:(SEL)action;
- (UIBarButtonItem*)customButtonItemWithImageName:(NSString*)imageName
                                           target:(id)target
                                           action:(SEL)action
                                            style:(UIControlContentHorizontalAlignment) style;

- (UIBarButtonItem*)moreButtonItemWithTarget:(id)target action:(SEL)action;
- (UIBarButtonItem*)shareButtonItemWithTarget:(id)target action:(SEL)action;

- (UIBarButtonItem*)grayButtonItemWithButton:(UIButton*)button;
- (UIBarButtonItem*)buttonItemWithButton:(UIButton*)button fontColor:(UIColor*)fontColor;
- (UIBarButtonItem*)buttonItemWithButton:(UIButton*)button
                               fontColor:(UIColor*)fontColor
                        highlightedColor:(UIColor*)highlightedColor;

- (void)showDarkBackButton;
- (void)showDarkBackButtonWithTarget:(id)target action:(SEL)action;
- (void)showWhiteBackButton;
- (void)showWhiteBackButtonWithTarget:(id)target action:(SEL)action;
- (void)showTransparentLeftButton;
- (void)showTransparentRightButton;
- (void)showTransparentBackButton;
- (void)showCancelButton;
- (void)showBlueCancelButton;
- (void)showGrayCancelButton;
- (void)showCloseButton;
- (void)showDarkCloseButton;
- (void)showGrayCloseIconButton;
- (void)showGrayCloseIconButton:(NavigationAlignment)alignment imageName:(NSString*)imageName;
- (void)setLeftItem:(UIBarButtonItem*)item;
- (void)setLeftItem:(UIBarButtonItem*)item marginOffset:(CGFloat)marginOffset;
- (void)setRightItem:(UIBarButtonItem*)item;
- (void)setRightItems:(NSArray*)barButtonItems;

- (void)setDarkSingleLineTitle:(NSString*)title;
- (void)setWhiteSingleLineTitle:(NSString*)title;
- (void)setAttributedContentTitle:(NSAttributedString*)title;
- (void)setTitle:(NSString*)title withLcFont:(LcFont*)lcFont;
- (void)setTitle:(NSString*)title subTitle:(NSAttributedString*)subtitle;
- (void)setLightContentTitle:(NSString*)title
                    subTitle:(NSAttributedString*)subtitle;
- (void)setDarkTitle:(NSString*)title subTitle:(NSAttributedString*)subtitle;
- (void)setLightAttributedContentTitle:(NSAttributedString*)title
                              subTitle:(NSAttributedString*)subtitle;


@property(nonatomic, assign) BOOL loadingIndicatorShowing;
- (void)showLoadingIndicator;
- (void)hideLoadingIndicator;

- (void)dismissToFromViewWithCompletion:(void (^)(void))completion;
- (void)popToFromViewController;

// for cellAdapter
- (void)setCellAdapter:(LcCellAdapter*)cellAdapter forTableView:(UITableView*)tableView;
- (void)addCellAdapter:(LcCellAdapter*)cellAdapter forTableView:(UITableView*)tableView;
- (void)closeEstimatedRowHeightforTableView:(UITableView*)tableView;

// LcNotificationDelegate
- (void)notificationReceived:(NSString*)notification auxiliary:(id)auxiliary;

// for subclass to override
// default return NO
- (BOOL)disallowDismissKeyboard;
- (void)dismissKeyboard;

// default enabled
- (void)disableInteractivePop:(BOOL)disabled;

/*
 * for subclass to override
 * default return current viewController name
 */
- (NSString*)hierarchyContext;

// application
- (void)addListenApplicationState;
- (void)removeListenApplicationState;
- (void)applicationWillResignActive;
- (void)applicationDidEnterBackground;
- (void)applicationWillEnterForeground;
- (void)applicationDidBecomeActive;
@end
